package com.abss.vote.util;

import com.abss.vote.service.RedisService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 点赞的定时任务
 */
public class LikeTask extends QuartzJobBean {

    @Autowired
    RedisService redisService;
    private SimpleDateFormat sdfg = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    private SimpleDateFormat sd = new SimpleDateFormat("mm:ss");

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //每天凌晨写入数据库(点赞信息)
        if(sdf.format(new Date()).equals("00:00:00")){
            System.out.println("爱不释书导入投票和浏览信息，时间：" + sdfg.format(new Date()));
             redisService.addUSERVOTESINFO();
             //保存点赞和浏览信息
             redisService.addUserVisitAndVoteInfoFromRedisToServer();
            System.out.println("爱不释书导入投票和浏览信息，时间：" + sdfg.format(new Date()));
        }

    }
}
